/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Validacion.ValidaCliente;
import java.awt.event.ItemEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import Modelo.Cliente;
import Validacion.ValidaCausa;
import javax.swing.JPanel;

/**
 *
 * @author bastian
 */
public class Panel_Causa extends javax.swing.JPanel {

    /**
     * Creates new form Panel_Cliente
     */
    public Panel_Causa() {
        initComponents();
    }
    
    
    private VentanaPrincipal V_Principal;
    private Panel_ReJudicial R_Judicial;
    
    public void setFrame(JFrame f){
        this.V_Principal= (VentanaPrincipal) f;
    }
    
    public void setPanel_Rejudicial (JPanel p){
        R_Judicial = (Panel_ReJudicial) p;
    }
    
    private void Limpiar(){
        this.TextField_Abogado.setText("");
        this.TextField_Caratulado.setText("");
        this.TextField_Juzgado.setText("");
        this.TextField_ROL.setText("");
        this.TextField_Receptor.setText("");
    }
    
    public ArrayList getDatos(){
        ArrayList datos = new ArrayList();
        
        datos.add(this.TextField_ROL.getText());
        datos.add(this.TextField_Receptor.getText());
        datos.add(this.TextField_Abogado.getText());
        datos.add(this.TextField_Caratulado.getText());
        datos.add(this.TextField_Juzgado.getText());
        
        
        return datos;
    
    }
    
    protected void CausaNueva(boolean b){
        this.Limpiar();
        
        this.jButton_BuscarROL.setEnabled(!b);
        
        this.TextField_Abogado.setEditable(b);
        this.TextField_Caratulado.setEditable(b);
        this.TextField_Juzgado.setEditable(b);
        this.TextField_Receptor.setEditable(b);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Label_Receptor = new javax.swing.JLabel();
        TextField_Receptor = new javax.swing.JTextField();
        Label_Abogado = new javax.swing.JLabel();
        TextField_Abogado = new javax.swing.JTextField();
        Label_ROL = new javax.swing.JLabel();
        Label_Juzgado = new javax.swing.JLabel();
        TextField_Juzgado = new javax.swing.JTextField();
        jLabel_Causa = new javax.swing.JLabel();
        TextField_ROL = new javax.swing.JTextField();
        TextField_Caratulado = new javax.swing.JTextField();
        Label_Caratulado = new javax.swing.JLabel();
        jButton_BuscarROL = new javax.swing.JButton();
        jButton_Cancelar = new javax.swing.JButton();
        label_Justicia481 = new Vista.Imagenes_Label.justicia.Label_Justicia48();
        jButton_RecepcionJudicial = new javax.swing.JButton();

        setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        setMaximumSize(new java.awt.Dimension(1000, 550));
        setMinimumSize(new java.awt.Dimension(1000, 550));
        setName("Cliente");
        setPreferredSize(new java.awt.Dimension(1000, 550));

        Label_Receptor.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_Receptor.setText("Receptor");

        TextField_Receptor.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_Receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_ReceptorKeyTyped(evt);
            }
        });

        Label_Abogado.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_Abogado.setText("Abogado");

        TextField_Abogado.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_Abogado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_AbogadoKeyTyped(evt);
            }
        });

        Label_ROL.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_ROL.setText("ROL Causa");

        Label_Juzgado.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_Juzgado.setText("Juzgado");

        TextField_Juzgado.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_Juzgado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_JuzgadoKeyTyped(evt);
            }
        });

        jLabel_Causa.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        jLabel_Causa.setText("Causa");

        TextField_ROL.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_ROL.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_ROLKeyTyped(evt);
            }
        });

        TextField_Caratulado.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        TextField_Caratulado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TextField_CaratuladoKeyTyped(evt);
            }
        });

        Label_Caratulado.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        Label_Caratulado.setText("Caratulado como");

        jButton_BuscarROL.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_BuscarROL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/buscar/24.png"))); // NOI18N
        jButton_BuscarROL.setText("Buscar");

        jButton_Cancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/cruz/24.png"))); // NOI18N
        jButton_Cancelar.setText("Cancelar");
        jButton_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelarActionPerformed(evt);
            }
        });

        jButton_RecepcionJudicial.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jButton_RecepcionJudicial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Vista/Imagenes_Files/justicia/24.png"))); // NOI18N
        jButton_RecepcionJudicial.setText("Agregar Recepción Judicial");
        jButton_RecepcionJudicial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_RecepcionJudicialActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jButton_RecepcionJudicial)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_Cancelar))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel_Causa)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(label_Justicia481, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 207, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Label_Receptor)
                            .addComponent(TextField_Receptor, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Label_Abogado)
                            .addComponent(TextField_Abogado, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Label_Juzgado)
                            .addComponent(TextField_Juzgado, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(Label_Caratulado)
                            .addComponent(TextField_Caratulado, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(Label_ROL)
                                .addGap(18, 18, 18)
                                .addComponent(TextField_ROL, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_BuscarROL)))
                        .addGap(177, 177, 177))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_Causa)
                    .addComponent(label_Justicia481, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Label_ROL)
                            .addComponent(TextField_ROL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jButton_BuscarROL))
                .addGap(38, 38, 38)
                .addComponent(Label_Receptor)
                .addGap(6, 6, 6)
                .addComponent(TextField_Receptor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(Label_Abogado)
                .addGap(6, 6, 6)
                .addComponent(TextField_Abogado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Label_Juzgado)
                .addGap(6, 6, 6)
                .addComponent(TextField_Juzgado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(Label_Caratulado)
                .addGap(6, 6, 6)
                .addComponent(TextField_Caratulado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_Cancelar)
                    .addComponent(jButton_RecepcionJudicial))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_BuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_BuscarActionPerformed
        // TODO add your handling code here:
        V_Principal.addPanel_Busqueda_Cliente(1);
    }//GEN-LAST:event_jButton_BuscarActionPerformed

    private void TextField_ReceptorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_ReceptorKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((!Character.isWhitespace(c)
                && !Character.isLetter(c)) || this.TextField_Receptor.getText().length() > 100) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_ReceptorKeyTyped

    private void TextField_AbogadoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_AbogadoKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((!Character.isWhitespace(c)
                && !Character.isLetter(c)) || this.TextField_Abogado.getText().length() > 100) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_AbogadoKeyTyped

    private void TextField_JuzgadoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_JuzgadoKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if (this.TextField_Juzgado.getText().length() > 100) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_JuzgadoKeyTyped

    private void TextField_ROLKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_ROLKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ( (c!='-' && !Character.isDigit(c)) || this.TextField_ROL.getText().length() > 10) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_ROLKeyTyped

    private void TextField_CaratuladoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TextField_CaratuladoKeyTyped
        // TODO add your handling code here:
        char c = evt.getKeyChar();
        if ((!Character.isWhitespace(c)
                && !Character.isLetter(c)) || this.TextField_Caratulado.getText().length() > 100) {
            evt.consume();
        }
    }//GEN-LAST:event_TextField_CaratuladoKeyTyped

    private void jButton_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelarActionPerformed
        // TODO add your handling code here:
        this.Limpiar();
        V_Principal.removePanel_Causa();
    }//GEN-LAST:event_jButton_CancelarActionPerformed

    private void jButton_RecepcionJudicialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_RecepcionJudicialActionPerformed
        // TODO add your handling code here:
        
        //REVISAR SI LA CAUSA YA EXISTE
        if(ValidaCausa.CausaValida(this.getDatos())){
            R_Judicial.Causa = this.getDatos();
            R_Judicial.TextField_Rol.setText(this.TextField_ROL.getText());
            R_Judicial.TextField_Rol.setEditable(false);

            V_Principal.addPanel_ReJudicial(true);
            V_Principal.bloquearPanel();
        }
        
        else
            JOptionPane.showMessageDialog(V_Principal, "Datos Incorrectos", "Error", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_jButton_RecepcionJudicialActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Label_Abogado;
    private javax.swing.JLabel Label_Caratulado;
    private javax.swing.JLabel Label_Juzgado;
    private javax.swing.JLabel Label_ROL;
    private javax.swing.JLabel Label_Receptor;
    private javax.swing.JTextField TextField_Abogado;
    private javax.swing.JTextField TextField_Caratulado;
    private javax.swing.JTextField TextField_Juzgado;
    private javax.swing.JTextField TextField_ROL;
    private javax.swing.JTextField TextField_Receptor;
    private javax.swing.JButton jButton_BuscarROL;
    private javax.swing.JButton jButton_Cancelar;
    private javax.swing.JButton jButton_RecepcionJudicial;
    private javax.swing.JLabel jLabel_Causa;
    private Vista.Imagenes_Label.justicia.Label_Justicia48 label_Justicia481;
    // End of variables declaration//GEN-END:variables
}
